package cn.signalpha.modules.shop.controller.seller;

import cn.signalpha.common.constant.AppConstant;
import cn.signalpha.core.boot.ctrl.BaseController;
import cn.signalpha.core.mp.support.Condition;
import cn.signalpha.core.mp.support.Query;
import cn.signalpha.core.tool.api.R;
import cn.signalpha.core.tool.utils.Func;
import cn.signalpha.modules.shop.entity.Transport;
import cn.signalpha.modules.shop.service.TransportService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;


@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_SHOP_NAME + "/sys-seller/transport")
@Api(value = "运费模版", tags = "运费模版")
public class SpiTransportController extends BaseController {

	private final TransportService transportService;

    @GetMapping("/page")
    @ApiOperation(value = "分页", notes = "")
    public R<IPage<Transport>> page(@ApiIgnore @RequestParam Map<String, Object> params, Query query) {
		QueryWrapper<Transport> queryWrapper = Condition.getQueryWrapper(params, Transport.class);
		queryWrapper.lambda().eq(Transport::getSellerId, getUser().getTenantId());
        return R.data(transportService.page(Condition.getPage(query), queryWrapper.lambda()));
    }

	@GetMapping("/list")
	@ApiOperation(value = "列表", notes = "")
	public R<List<Transport>> list(@ApiIgnore @RequestParam Map<String, Object> params) {
		QueryWrapper<Transport> queryWrapper = Condition.getQueryWrapper(params, Transport.class);
		queryWrapper.lambda().eq(Transport::getSellerId, getUser().getTenantId());
		return R.data(transportService.list(queryWrapper));
	}

	@GetMapping("/info")
	@ApiOperation(value = "详情", notes = "传入id")
	public R<Transport> info(@RequestParam Long id) {
		return R.data(transportService.getTransport(id));
	}

	@PostMapping("/submit")
	@ApiOperation(value = "提交", notes = "传入transport")
	public R submit(@Valid @RequestBody Transport transport) {
		transport.setSellerId(Long.valueOf(getUser().getTenantId()));
		return R.status(transportService.submit(transport));
	}

	@PostMapping("/remove")
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(transportService.removeTransport(Func.toLongList(ids)));
	}

}
